const express = require('express');
const app = express()
var cors = require('cors')
app.use(express.json())
app.use(cors())

app.post("/login",(req,res)=>{
    let count = req.body.Account
    let psw = req.body.Password
    // console.log(req,count,psw)
    if(count == "admin" && psw =="11111"){
        res.json({
            id:1,
            msg:"success"
        })
    }else if(count == "admin2" && psw =="11111"){
        res.json({
            id:2,
            msg:"success"
        })
    }else if(count == "admin3" && psw =="11111"){
        res.json({
            id:3,
            msg:"success"
        })
    }else{
        res.json({
            id:3,
            msg:"fail"
        })
    }
})

app.post("/getroutes",(req,res)=>{
    console.log("getroutes",req.body)
    let id = req.body.id
    if(id == 1){
        res.json({
            data:[
                {
                    path:"/page2",
                    component:"Page2"
                },
                {
                    path:"/page3",
                    component:"Page3",
                    children:[
                        {
                            path:'son1',
                            component:"page3Son1"
                        }
                    ]
                }
            ]
        })
    }else if(id == 2){
        res.json({
            data:[
                {
                    path:"/page1",
                    component:"Page1"
                },
                {
                    path:"/page3",
                    component:"Page3",
                    children:[
                        {
                            path:'son1',
                            component:"page3Son1"
                        }
                    ]
                }
            ]
        })
    }else if(id == 3){
        res.json(
            {
                data:[
                    {
                        path:"/page1",
                        component:"Page1"
                    },
                    {
                        path:"/page2",
                        component:"Page2"
                    }
                ]
            }
        )
    }
})


app.listen(8001,()=>{
    console.log("服务成功 端口：8001")
})

